package xcmg.device.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobContext;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class XxlJobs {
    private static Logger logger = LoggerFactory.getLogger(XxlJobs.class);


    @Autowired
    private SyncGpsTask syncGpsTask;

    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("demoJobHandler")
    public ReturnT<String> demoJobHandler()throws Exception {
        logger.info("XXL-JOB, Hello World.");
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        for (int i = 0; i < 5; i++) {
            logger.info(s+" beat at:" + i);
            TimeUnit.SECONDS.sleep(2);
        }
        return ReturnT.SUCCESS;
    }

    @XxlJob("syncGpsPartSupplierHandler")
    public ReturnT<String> syncGpsPartSupplier(){
        logger.info("syncGpsPartSupplier begin.");
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        syncGpsTask.syncGpsPartSupplier(s);
        logger.info("syncGpsPartSupplier end.");
        return ReturnT.SUCCESS;
    }
    @XxlJob("syncAllTimeGpsPartSupplierHandler")
    public ReturnT<String> syncAllTimeGpsPartSupplierHandler(){
        logger.info("syncGpsPartSupplier begin.");
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        syncGpsTask.syncAllTimeGpsPartSupplierHandler(s);
        logger.info("syncGpsPartSupplier end.");
        return ReturnT.SUCCESS;
    }

    @XxlJob("syncGpsPartInfoHandler")
    public ReturnT<String> syncGpsPartInfo(){
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        logger.info("syncGpsPartInfo begin.");
        syncGpsTask.syncGpsPartInfo(s);
        logger.info("syncGpsPartInfo end.");
        return ReturnT.SUCCESS;
    }

    @XxlJob("syncGpsMmSwOrderHandler")
    public ReturnT<String> syncGpsMmSwOrderHandler(){
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        logger.info("syncGpsMmSwOrderHandler begin.");
        syncGpsTask.syncGpsMmSwOrder(s);
        logger.info("syncGpsMmSwOrderHandler end.");
        return ReturnT.SUCCESS;
    }

    @XxlJob("syncSupplierNoGpsMmSwOrderHandler")
    public ReturnT<String> syncSupplierNoGpsMmSwOrderHandler() {
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();

        logger.info("syncSupplierNoGpsMmSwOrderHandler begin.");
        syncGpsTask.syncSupplierNoGpsMmSwOrderHandler(s);
        logger.info("syncSupplierNoGpsMmSwOrderHandler end.");
        return ReturnT.SUCCESS;
    }

    //根据供应商全量同步条码表
    @XxlJob("syncSupplierNoGpsMmSwOrderLabelHandler")
    public ReturnT<String> syncSupplierNoGpsMmSwOrderLabelHandler() {
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        logger.info("syncSupplierNoGpsMmSwOrderLabelHandler begin.");
        syncGpsTask.syncSupplierNoGpsMmSwOrderLabelHandler(s);
        logger.info("syncSupplierNoGpsMmSwOrderLabelHandler end.");
        return ReturnT.SUCCESS;
    }

    @XxlJob("syncGpsMmSwOrderLabelHandler")
    public ReturnT<String> syncGpsMmSwOrderLabelHandler() {
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        logger.info("syncSupplierNoGpsMmSwOrderLabelHandler begin.");
        syncGpsTask.syncGpsMmSwOrderLabelHandler(s);
        logger.info("syncSupplierNoGpsMmSwOrderLabelHandler end.");
        return ReturnT.SUCCESS;
    }




    @XxlJob("syncGpsMmJisoPoHeadHandler")
    public ReturnT<String> syncGpsMmJisoPoHeadHandler(){
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        logger.info("syncGpsMmJisoPoHeadHandler begin.");
        syncGpsTask.syncGpsMmJisoPoHeadHandler(s);
        logger.info("syncGpsMmJisoPoHeadHandler end.");
        return ReturnT.SUCCESS;
    }

    @XxlJob("syncSupplierGpsMmJisoPoHeadHandler")
    public ReturnT<String> syncSupplierGpsMmJisoPoHeadHandler() {
        XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext();
        String s = xxlJobContext.getJobParam();
        logger.info("syncSupplierGpsMmJisoPoHeadHandler begin.");
        syncGpsTask.syncSupplierGpsMmJisoPoHeadHandler(s);
        logger.info("syncSupplierGpsMmJisoPoHeadHandler end.");
        return ReturnT.SUCCESS;
    }
}
